<template>
    <div class="pt22 pl17 pr22 bgfff box_shadow_04 minh400">
        <div class="disflex jusbet">
            <span class="fs14 c999 pt20">已有商友号？<i class="curpointer cred" @click="tologin">登录</i></span>
            <span class="lh30 pl21 pr22 bgred cfff fs14 curpointer h30 mt15" @click="confirmRegister">注册</span>
        </div>
        <div class="pl10 pr10 mb18 fs14 w100p bgf5 mt23">
            <i class="iconfont icon-iconrenwu fs16 c89 lh40"></i>
            <input type="text" v-model="username" class="pl14 lh40 bgf5 boradius1" placeholder="您的姓名~" @keyup.enter="confirmRegister">
        </div>
        <div class="pl10 pr10 mb18 fs14 w100p bgf5">
            <i class="iconfont icon-dianhua fs16 c89 lh40"></i>
            <input type="tel" v-model="tel" class="pl14 lh40 bgf5 boradius1" placeholder="您的电话~" @keyup.enter="confirmRegister">
        </div>
        <div class="pl10 pr10 mb18 fs14 w100p bgf5">
            <i class="iconfont icon-mima fs16 c89 lh40"></i>
            <input type="password" v-model="pwd" class="pl14 lh40 bgf5 boradius1" placeholder="登录密码~" @keyup.enter="confirmRegister">
        </div>
        <textarea name="" id="" class="w100p p1612 bgf5 fs14 c999 boradius1 h100" placeholder="添加您的货物买卖需求～" @keyup.enter="confirmRegister" v-model="text"></textarea>
    </div>
</template>

<script>
    export default {
        name: "Login",
        data(){
            return{
                username:'',
                tel:'',
                text:'',
                pwd:''
            }
        },
        methods:{
            tologin(){
                this.$emit('tologin')
            },
            confirmRegister(){
                var v = this;
                if(!v.username.trim()){
                    this.$message.error('请输入您的姓名！');
                    return
                }
                if(!v.tel.trim()){
                    this.$message.error('请输入手机号！');
                    return
                }
                if(!v.pwd.trim()){
                    this.$message.error('请输入密码！');
                    return
                }
                if(!v.$telReg(v.tel.trim())){
                    this.$message.error('请输入正确的手机号！');
                    return
                }
                if(!v.text.trim()){
                    this.$message.error('请输入您的购买需求！');
                    return
                }
                var params = new FormData();
                params.append('mobile',v.tel.trim());
                params.append('password',v.pwd.trim());
                params.append('nickname',v.username.trim());
                params.append('text',v.text.trim());
                v.$axios.post('/index.php?g=user&m=register&a=doregister',params)
                    .then((res) => {
                        res = res.data;
                        if (res.result == 1) {
                            v.$message.success(res.msg || '注册成功！现在去登录');
                            v.pwd = '';
                            v.username = '';
                            v.text = '';
                            v.$emit('tologin');
                        } else {
                            v.$message.error(res.msg || '注册失败！请稍后再试');
                        }
                    }).catch((err) => {
                    console.log(err);
                    v.loading = false;
                    v.$message.error('注册失败！请稍后再试');

                });
            }
        }
    }
</script>

<style>

</style>



















